package com.engine.xfjt.duss.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.xfjt.duss.utils.WorkflowCreateHandler;
import com.engine.xfjt.duss.utils.XfjtUtil;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-03-28
 * @Description: 新发集团调用接口
 * @ModifyLog:
 **/

public class WeaXfjtWeb extends BaseBean {

    /**
     * @Description: 获取预览试卷信息接口
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @POST
    @Path("/getPreviewTest")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPreviewTest(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        XfjtUtil xfjtUtil = new XfjtUtil();
        String requestid = Util.null2String(request.getParameter("requestid"));
        writeLog(">>>>>getPreviewTest>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select id,ktszlx from formtable_main_295 where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String ktszlx = Util.null2String(rs.getString("ktszlx"));
            JSONArray dxtlist = new JSONArray();
            JSONArray duoxtlist = new JSONArray();
            JSONArray pdtlist = new JSONArray();
            JSONArray jdtlist = new JSONArray();
            String dxttitle = "";
            String duoxttitle = "";
            String pdttitle = "";
            String jdttitle = "";
            if (ktszlx.contains("0")) {
                rs.executeQuery("select tm,fz from formtable_main_295_dt1 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "0_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    dxtlist.add(dxtjson);
                    count++;
                }
                dxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("1")) {
                rs.executeQuery("select tm,fz from formtable_main_295_dt2 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "1_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    duoxtlist.add(dxtjson);
                    count++;
                }
                duoxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("2")) {
                rs.executeQuery("select tm,fz from formtable_main_295_dt3 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "2_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    pdtlist.add(dxtjson);
                    count++;
                }
                pdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("3")) {
                rs.executeQuery("select tm,fz from formtable_main_295_dt4 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "3_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    jdtlist.add(dxtjson);
                    count++;
                }
                jdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            apidatas.put("examtime", xfjtUtil.getformtKssc(requestid));
            apidatas.put("dxttitle", dxttitle);
            apidatas.put("duoxttitle", duoxttitle);
            apidatas.put("pdttitle", pdttitle);
            apidatas.put("jdttitle", jdttitle);
            apidatas.put("dxt", dxtlist);
            apidatas.put("duoxt", duoxtlist);
            apidatas.put("pdt", pdtlist);
            apidatas.put("jdt", jdtlist);
            writeLog(">>>>>getPreviewTest>>>apidatas=" + apidatas.toString());
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 获取开始考试试卷信息接口
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @POST
    @Path("/getWriteTest")
    @Produces({MediaType.TEXT_PLAIN})
    public String getWriteTest(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        XfjtUtil xfjtUtil = new XfjtUtil();
        String requestid = Util.null2String(request.getParameter("requestid"));
        writeLog(">>>>>getWriteTest>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select id,ktszlx from formtable_main_286 where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String ktszlx = Util.null2String(rs.getString("ktszlx"));
            JSONArray dxtlist = new JSONArray();
            JSONArray duoxtlist = new JSONArray();
            JSONArray pdtlist = new JSONArray();
            JSONArray jdtlist = new JSONArray();
            String dxttitle = "";
            String duoxttitle = "";
            String pdttitle = "";
            String jdttitle = "";
            if (ktszlx.contains("0")) {
                rs.executeQuery("select tm,fz from formtable_main_286_dt1 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "0_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    dxtlist.add(dxtjson);
                    count++;
                }
                dxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("1")) {
                rs.executeQuery("select tm,fz from formtable_main_286_dt2 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "1_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    duoxtlist.add(dxtjson);
                    count++;
                }
                duoxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("2")) {
                rs.executeQuery("select tm,fz from formtable_main_286_dt3 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "2_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    pdtlist.add(dxtjson);
                    count++;
                }
                pdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("3")) {
                rs.executeQuery("select tm,fz from formtable_main_286_dt4 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "3_" + count);
                    dxtjson.put("tm", tmname);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    jdtlist.add(dxtjson);
                    count++;
                }
                jdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            apidatas.put("examtime", xfjtUtil.getCountDown(requestid));
            apidatas.put("dxttitle", dxttitle);
            apidatas.put("duoxttitle", duoxttitle);
            apidatas.put("pdttitle", pdttitle);
            apidatas.put("jdttitle", jdttitle);
            apidatas.put("dxt", dxtlist);
            apidatas.put("duoxt", duoxtlist);
            apidatas.put("pdt", pdtlist);
            apidatas.put("jdt", jdtlist);
            writeLog(">>>>>getWriteTest>>>apidatas=" + apidatas.toString());

        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 获取审批考试试卷信息接口
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @POST
    @Path("/getApprovalTest")
    @Produces({MediaType.TEXT_PLAIN})
    public String getApprovalTest(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        XfjtUtil xfjtUtil = new XfjtUtil();
        String requestid = Util.null2String(request.getParameter("requestid"));
        writeLog(">>>>>getApprovalTest>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select id,ktszlx from formtable_main_286 where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String ktszlx = Util.null2String(rs.getString("ktszlx"));
            JSONArray dxtlist = new JSONArray();
            JSONArray duoxtlist = new JSONArray();
            JSONArray pdtlist = new JSONArray();
            JSONArray jdtlist = new JSONArray();
            String dxttitle = "";
            String duoxttitle = "";
            String pdttitle = "";
            String jdttitle = "";
            if (ktszlx.contains("0")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt1 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int txnr = Util.getIntValue(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "0_" + count);
                    dxtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", xfjtUtil.getKsxx(txnr));
                    dxtjson.put("da", dajson);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    dxtlist.add(dxtjson);
                    count++;
                }
                dxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("1")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt2 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject duoxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    duoxtjson.put("xh", "1_" + count);
                    duoxtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", "");
                    duoxtjson.put("child", tmjson.getJSONArray("child"));
                    duoxtlist.add(duoxtjson);
                    count++;
                }
                duoxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("2")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt3 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject pdtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    pdtjson.put("xh", "2_" + count);
                    pdtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", xfjtUtil.getPdtxx(tm, txnr));
                    pdtjson.put("da", dajson);
                    pdtjson.put("child", tmjson.getJSONArray("child"));
                    pdtlist.add(pdtjson);
                    count++;
                }
                pdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("3")) {
                rs.executeQuery("select tm,fz,px,txnr from formtable_main_286_dt4 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject jdtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    jdtjson.put("xh", "3_" + count);
                    jdtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    dajson.put("xzdaid", "1");
                    dajson.put("xzdamc", txnr);
                    jdtjson.put("da", dajson);
                    jdtjson.put("child", tmjson.getJSONArray("child"));
                    jdtlist.add(jdtjson);
                    count++;
                }
                jdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            apidatas.put("examtime", xfjtUtil.getformtKssc(requestid));
            apidatas.put("dxttitle", dxttitle);
            apidatas.put("duoxttitle", duoxttitle);
            apidatas.put("pdttitle", pdttitle);
            apidatas.put("jdttitle", jdttitle);
            apidatas.put("dxt", dxtlist);
            apidatas.put("duoxt", duoxtlist);
            apidatas.put("pdt", pdtlist);
            apidatas.put("jdt", jdtlist);
            writeLog(">>>>>getApprovalTest>>>apidatas=" + apidatas.toString());
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 获取浏览考试试卷信息接口
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @POST
    @Path("/getBrowseTest")
    @Produces({MediaType.TEXT_PLAIN})
    public String getBrowseTest(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        XfjtUtil xfjtUtil = new XfjtUtil();
        String requestid = Util.null2String(request.getParameter("requestid"));
        writeLog(">>>>>getApprovalTest>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select id,ktszlx from formtable_main_286 where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String ktszlx = Util.null2String(rs.getString("ktszlx"));
            JSONArray dxtlist = new JSONArray();
            JSONArray duoxtlist = new JSONArray();
            JSONArray pdtlist = new JSONArray();
            JSONArray jdtlist = new JSONArray();
            String dxttitle = "";
            String duoxttitle = "";
            String pdttitle = "";
            String jdttitle = "";

            if (ktszlx.contains("0")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt1 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject dxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    int txnr = Util.getIntValue(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    dxtjson.put("xh", "0_" + count);
                    dxtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", xfjtUtil.getKsxx(txnr));
                    JSONObject zqdnJson = xfjtUtil.getRightAnswer(tm);
                    JSONArray zqdaList = JSONArray.parseArray(zqdnJson.getString("zqda"));
                    int zqdaid = zqdaList.getJSONObject(0).getIntValue("xxid");
                    dajson.put("zqdaid", zqdaid);
                    dajson.put("xzdamc", xfjtUtil.getKsxx(zqdaid));
                    dxtjson.put("da", dajson);
                    dxtjson.put("child", tmjson.getJSONArray("child"));
                    dxtlist.add(dxtjson);
                    count++;
                }
                dxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("1")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt2 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject duoxtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    duoxtjson.put("xh", "1_" + count);
                    duoxtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    JSONObject zqdnJson = xfjtUtil.getRightAnswer(tm);
                    JSONArray zqdaList = JSONArray.parseArray(zqdnJson.getString("zqda"));
                    String zqdaids = "";
                    for (int j = 0; j < zqdaList.size(); j++) {
                        String zqdaid = zqdaList.getJSONObject(j).getString("xxid");
                        zqdaids +="".equals(zqdaids)?zqdaid:","+zqdaid;
                    }
                    dajson.put("zqdaid", zqdaids);
                    dajson.put("zqdamc", "");
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", "");
                    duoxtjson.put("da", dajson);
                    duoxtjson.put("child", tmjson.getJSONArray("child"));
                    duoxtlist.add(duoxtjson);
                    count++;
                }
                duoxttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("2")) {
                rs.executeQuery("select tm,fz,txnr from formtable_main_286_dt3 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject pdtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    pdtjson.put("xh", "2_" + count);
                    pdtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    JSONObject zqdnJson = xfjtUtil.getRightAnswer(tm);
                    JSONArray zqdaList = JSONArray.parseArray(zqdnJson.getString("zqda"));
                    String zqdaid = zqdaList.getJSONObject(0).getString("xxid");
                    String xxnr = zqdaList.getJSONObject(0).getString("xxnr");
                    dajson.put("zqdaid", zqdaid);
                    dajson.put("zqdamc", xxnr);
                    dajson.put("xzdaid", txnr);
                    dajson.put("xzdamc", xfjtUtil.getPdtxx(tm, txnr));
                    pdtjson.put("da", dajson);
                    pdtjson.put("child", tmjson.getJSONArray("child"));
                    pdtlist.add(pdtjson);
                    count++;
                }
                pdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            if (ktszlx.contains("3")) {
                rs.executeQuery("select tm,fz,px,txnr from formtable_main_286_dt4 where mainid=?", mainid);
                int count = 0;
                int fzs = 0;
                while (rs.next()) {
                    JSONObject jdtjson = new JSONObject();
                    String tm = Util.null2String(rs.getString("tm"));
                    String txnr = Util.null2String(rs.getString("txnr"));
                    int fz = Util.getIntValue(rs.getString("fz"));
                    fzs += fz;
                    JSONObject tmjson = xfjtUtil.getKstmxx(tm);
                    String tmname = tmjson.getString("tmname");
                    jdtjson.put("xh", "3_" + count);
                    jdtjson.put("tm", tmname);
                    JSONObject dajson = new JSONObject();
                    JSONObject zqdnJson = xfjtUtil.getRightAnswer(tm);
                    JSONArray zqdaList = JSONArray.parseArray(zqdnJson.getString("zqda"));
                    String zqdaid = zqdaList.getJSONObject(0).getString("xxid");
                    String xxnr = zqdaList.getJSONObject(0).getString("xxnr");
                    dajson.put("zqdaid", zqdaid);
                    dajson.put("zqdamc", xxnr);
                    dajson.put("xzdaid", "1");
                    dajson.put("xzdamc", txnr);
                    jdtjson.put("da", dajson);
                    jdtjson.put("child", tmjson.getJSONArray("child"));
                    jdtlist.add(jdtjson);
                    count++;
                }
                jdttitle = "共" + count + "题，合计" + fzs + "分";
            }
            apidatas.put("examtime", xfjtUtil.getformtKssc(requestid));
            apidatas.put("dxttitle", dxttitle);
            apidatas.put("duoxttitle", duoxttitle);
            apidatas.put("pdttitle", pdttitle);
            apidatas.put("jdttitle", jdttitle);
            apidatas.put("dxt", dxtlist);
            apidatas.put("duoxt", duoxtlist);
            apidatas.put("pdt", pdtlist);
            apidatas.put("jdt", jdtlist);
            writeLog(">>>>>getApprovalTest>>>apidatas=" + apidatas.toString());
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 创建公文借阅流程
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @GET
    @Path("/createBorrowDocWf")
    @Produces({MediaType.TEXT_PLAIN})
    public String createBorrowDocWf(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        BaseBean baseBean = new BaseBean();
        String workflowId = "25";//流程ID
        String workflowName = "公文借阅";//流程名称
        String IsNextFlow = "1";//是否提交下一节点
        String curdate = DateUtil.getCurrentDate();
        XfjtUtil xfjtUtil = new XfjtUtil();
        boolean flag = false;
        try {
            ResourceComInfo rci = new ResourceComInfo();
            //0:收文，1：发文
            String type = Util.null2String(request.getParameter("type"));
            //userid
            String userid = Util.null2String(request.getParameter("userid"));
            String departmentid = xfjtUtil.getDepartAndSub(userid).get("departmentid");
            String subcompanyid = xfjtUtil.getDepartAndSub(userid).get("subcompanyid");
            //流程名称
            String requestName = workflowName + "-" + rci.getLastname(userid) + "-" + curdate;
            //建模数据ID
            String ids = Util.null2String(request.getParameter("ids"));
            baseBean.writeLog(">>>>>>createBorrowDocWf>>>>>ids=" + ids);
            Map<String, String> requestMainMap = new HashMap<String, String>();
            //	借阅人
            requestMainMap.put("jyr", userid);
            //借阅公司
            requestMainMap.put("jygs", Util.null2String(subcompanyid));
            //借阅部门
            requestMainMap.put("jybm", Util.null2String(departmentid));
            //借阅日期
            requestMainMap.put("jyrq", curdate);

            WorkflowCreateHandler handler = new WorkflowCreateHandler();
            String requestid = handler.WorkflowCreateByRequestMap(userid, workflowId, requestName, IsNextFlow, requestMainMap);
            if (Util.getIntValue(requestid) > 0) {
                xfjtUtil.addDetailData(type, requestid, ids);
                flag = true;
            }
            apidatas.put("api_status", flag);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", flag);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 创建公文交换流程
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @GET
    @Path("/createExchangeDocWf")
    @Produces({MediaType.TEXT_PLAIN})
    public String createExchangeDocWf(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        BaseBean baseBean = new BaseBean();
        String workflowId = "26";//流程ID
        String workflowName = "公文交换";//流程名称
        String IsNextFlow = "0";//是否提交下一节点
        String curdate = DateUtil.getCurrentDate();
        XfjtUtil xfjtUtil = new XfjtUtil();
        boolean flag = false;
        try {
            ResourceComInfo rci = new ResourceComInfo();
            User user = HrmUserVarify.getUser(request, response);
            String userid = user.getUID() + "";
            String type = Util.null2String(request.getParameter("type"));//0:收文，1：发文
            String departmentid = xfjtUtil.getDepartAndSub(userid).get("departmentid");
            String subcompanyid = xfjtUtil.getDepartAndSub(userid).get("subcompanyid");
            String requestName = workflowName + "-" + rci.getLastname(userid) + "-" + curdate;//流程名称
            String id = Util.null2String(request.getParameter("id"));//建模数据ID
            baseBean.writeLog(">>>>>>createExchangeDocWf>>>>>id=" + id);
            Map<String, String> requestMainMap = new HashMap<String, String>();
            requestMainMap.put("fqr", userid);//	发起人
            requestMainMap.put("fqgs", Util.null2String(subcompanyid));//发起公司
            requestMainMap.put("fqbm", Util.null2String(departmentid));//发起部门
            requestMainMap.put("fqrq", curdate);//发起日期
            requestMainMap.put("jhwjly", "0");//交换文件来源
            Map<String, String> resultMap = xfjtUtil.getExchangeDocData(type, id);
            requestMainMap.put("gwlx", Util.null2String(resultMap.get("gwlx")));//公文类型
            requestMainMap.put("xzxtfw", Util.null2String(resultMap.get("xzxtfw")));//选择系统发文
            requestMainMap.put("xzxtsw", Util.null2String(resultMap.get("xzxtsw")));//选择系统收文
            requestMainMap.put("oaxtwj", Util.null2String(resultMap.get("oaxtwj")));//OA系统文件
            requestMainMap.put("gwmc", Util.null2String(resultMap.get("gwmc")));//公文名称
            requestMainMap.put("wh", Util.null2String(resultMap.get("wh")));//文号
            baseBean.writeLog(">>>>>>requestMainMap=" + requestMainMap.toString());
            WorkflowCreateHandler handler = new WorkflowCreateHandler();
            String requestid = handler.WorkflowCreateByRequestMap(userid, workflowId, requestName, IsNextFlow, requestMainMap);
            if (Util.getIntValue(requestid) > 0) {
                flag = true;
            }
            apidatas.put("api_status", flag);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", flag);
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * @Description: 已借阅公文查询列表点击收回借阅按钮修改状态并写入日期
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/12
     */
    @GET
    @Path("/backBorrowed")
    @Produces({MediaType.TEXT_PLAIN})
    public String backBorrowed(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        BaseBean baseBean = new BaseBean();
        RecordSet rs = new RecordSet();
        String curdate = DateUtil.getCurrentDate();
        boolean flag = false;
        try {
            String ids = Util.null2String(request.getParameter("ids"));//建模数据ID
            baseBean.writeLog(">>>>>>backBorrowed>>>>>ids=" + ids);
            flag = rs.executeUpdate("update uf_yjygw set jyzt=2,ghrq='" + curdate + "' where id in (" + ids + ") and jyzt=0");
            apidatas.put("api_status", flag);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", flag);
        }
        return JSONObject.toJSONString(apidatas);
    }


}
